<?php

namespace App\Admin\Controllers;

use App\Services\PreDzlabQwenVersionService;
use Slowlyo\OwlAdmin\Controllers\AdminController;

/**
 * 个人套餐
 *
 * @property PreDzlabQwenVersionService $service
 */
class PreDzlabQwenVersionController extends AdminController
{
	protected string $serviceName = PreDzlabQwenVersionService::class;

	public function list()
	{
		$crud = $this->baseCRUD()
			->filterTogglable(false)
			->headerToolbar([
				$this->createButton('dialog'),
				...$this->baseHeaderToolBar()
			])
			->columns([
				amis()->TableColumn('id', 'ID'),
				amis()->TableColumn('name', '名称'),
				amis()->TableColumn('model.name', '关联模型'),
				amis()->TableColumn('num', '免费次数'),
				amis()->TableColumn('price', '积分数'),
				amis()->TableColumn('days', '有效期(天数)'),
				amis()->TableColumn('displayorder', '顺序(越小越靠前)'),
				amis()->Operation()->label(admin_trans('admin.actions'))->buttons([
					$this->rowEditButton('dialog'),
					$this->rowDeleteButton(),
				])
			]);

		return $this->baseList($crud);
	}

	public function form($isEdit = false)
	{
		return $this->baseForm()->body([
			amis()->TextControl('name', '名称')->required(),
			amis()->NumberControl('num', '免费次数')->value(0)->min(0)->required(),
			amis()->TextControl('price', '积分数')->required(),
			amis()->NumberControl('days', '有效期')->min(1)->required()->labelRemark([
				'icon' => 'fa fa-question-circle',
				'trigger' => [
					'0' => 'hover',
				],
				'className' => 'Remark--warning',
				'placement' => 'top',
				'content' => '单位：天',
			]),
			amis()->NumberControl('displayorder', '顺序')->min(1)->required()->labelRemark([
				'icon' => 'fa fa-question-circle',
				'trigger' => [
					'0' => 'hover',
				],
				'className' => 'Remark--warning',
				'placement' => 'top',
				'content' => '越小越靠前',
			]),
			amis()->SelectControl('model_id', '关联模型')->source('aq_models?_action=getData&perPage=99999')->labelField('name')->valueField('id')->selectFirst('1'),
		]);
	}

	public function detail()
	{
		return $this->baseDetail()->body([
			amis()->TextControl('id', 'ID')->static(),
			amis()->TextControl('name', 'Name')->static(),
			amis()->TextControl('num', 'Num')->static(),
			amis()->TextControl('price', 'Price')->static(),
			amis()->TextControl('days', 'Days')->static(),
			amis()->TextControl('displayorder', 'Displayorder')->static(),
			amis()->TextControl('type', 'Type')->static(),
		]);
	}
}
